home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / hsrc_117.zip / SHELP.C < prev    next >
Text File  |  1990-11-09  |  3KB  |  148 lines

  1. /* SHelp.C File -- uses SHARE i/o */
  2.  
  3. #include <stdio.h>
  4. #include <io.h>
  5. #include <fcntl.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <conio.h>
  9. #include <dos.h>
  10. #include "twindow.h"
  11. #include "keys.h"
  12.  
  13. extern char * pascal fgetsx(char *,int,int);
  14. extern long tell(int);
  15. extern unsigned char usemouse;
  16.  
  17. #define MAXHELPS 150
  18. #define HBG WHITE
  19. #define HFG BLACK
  20. #define HINT DIM
  21.  
  22. #define TRUE  1
  23. #define FALSE 0
  24.  
  25. static struct helps {
  26.   char hname[9];
  27.   int h,w;
  28.   long hptr;
  29. } hps [MAXHELPS+1];
  30.  
  31. static int hp=0;
  32. static int ch=0;
  33. static int hx,hy;
  34. int helpfp=-1;
  35. void help();
  36. char helpname[132];
  37. void pascal getline(char *lineh);
  38.  
  39. /* Load the HELP! definition file */
  40.  
  41. void pascal load_help (char *hn) {
  42.  
  43.   extern void (*helpfunc)();
  44.   extern int helpkey;
  45.   char lineh[80];
  46.  
  47.   if (strcmp(helpname,hn)==0)
  48.     return;
  49.   helpfunc=help;
  50.   helpkey=F1;
  51.   hp=0;
  52.   strcpy(helpname,hn);
  53.   if((helpfp=_open(helpname,O_RDONLY | O_TEXT | O_DENYNONE))==-1)
  54.     return;
  55.   getline(lineh);
  56.   while(1) {
  57.     if(hp==MAXHELPS)
  58.       break;
  59.     if (strncmp(lineh,"<end>",5)==0)
  60.       break;
  61.     if (*lineh != '<')
  62.       continue;
  63.     hps[hp].h=3;
  64.     hps[hp].w=18;
  65.     strncpy(hps[hp].hname,lineh+1,8);
  66.     hps[hp].hptr=tell(helpfp);
  67.     getline(lineh);
  68.     while (*lineh!='<') {
  69.       hps[hp].h++;
  70.       hps[hp].w=max(hps[hp].w,strlen(lineh)+2);
  71.       getline(lineh);
  72.     }
  73.     hp++;
  74.   }
  75.   _close(helpfp);
  76. }
  77.  
  78. /* Get a line of text from the help file */
  79.  
  80. static void pascal getline(char *lineh)
  81. {
  82.   if(fgetsx(lineh,80,helpfp)==NULL)
  83.     strcpy(lineh,"<end>");
  84. }
  85.  
  86. /* Set the current active help screen */
  87.  
  88. void pascal set_help(char *s,int x,int y)
  89. {
  90.   for (ch=0;ch<hp;ch++)
  91.     if (strncmp(s,hps[ch].hname,8)==0)
  92.       break;
  93.   hx=x;
  94.   hy=y;
  95. }
  96.  
  97. /* Display the current help window */
  98.  
  99. void help() {
  100.  
  101.   char ln[80];
  102.   int i,xx,yy;
  103.   WINDOW *wnd;
  104.   extern int helpkey;
  105.  
  106.   if((helpfp=_open(helpname,O_RDONLY | O_TEXT | O_DENYNONE))==-1)
  107.     return;
  108.   if (hp && ch !=hp) {
  109.     curr_cursor(&xx,&yy);
  110.     cursor(0,25);
  111.     wnd=establish_window(hx,hy,hps[ch].h,hps[ch].w);
  112.     set_title(wnd," Help! ");
  113.     set_colors(wnd,ALL,HBG,HFG,HINT);
  114.     set_border(wnd,5);
  115.     display_window(wnd);
  116.     lseek(helpfp,hps[ch].hptr,0);
  117.     for(i=0;i<hps[ch].h-3;i++) {
  118.       getline(ln);
  119.       wprintf(wnd,ln);
  120.     }
  121.     wprintf(wnd," <<Continue>>");
  122.     while (!kbhit()) {
  123.         if(usemouse) {
  124.  
  125.             union REGS rg;
  126.  
  127.             rg.x.ax=5;
  128.             rg.x.bx=0;
  129.             int86(0x33,&rg,&rg);
  130.             if(rg.x.bx) break;
  131.             rg.x.ax=5;
  132.             rg.x.bx=1;
  133.             int86(0x33,&rg,&rg);
  134.             if(rg.x.bx) break;
  135.             rg.x.ax=5;
  136.             rg.x.bx=2;
  137.             int86(0x33,&rg,&rg);
  138.             if(rg.x.bx) break;
  139.  
  140.         }
  141.     }
  142.     delete_window(wnd);
  143.     cursor(xx,yy);
  144.   }
  145.   _close(helpfp);
  146. }
  147.  
  148.